//
//  UWOADViewController.m
//  basic
//
//  Created by Jack on 2016/12/17.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "UWOADViewController.h"
#import "AppDelegate+RootController.h"
#import "UIImageView+WebCache.h"

@interface UWOADViewController ()

@property(nonatomic,copy) NSString *img_url;
@property(nonatomic,strong) NSTimer *myTimer;
@property(nonatomic,strong) UIImageView *adImageView;

@end

@implementation UWOADViewController

@synthesize adImageView,img_url;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    adImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW,kScreenH)];
    adImageView.userInteractionEnabled = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:adImageView];
    _myTimer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(timerFired) userInfo:nil repeats:NO];
    [[NSRunLoop  currentRunLoop] addTimer:_myTimer forMode:NSDefaultRunLoopMode];
    [self.navigationController setNavigationBarHidden: YES];
    
    self.adImageView.alpha = 0;
    
    img_url = @"http://cdn.duitang.com/uploads/item/201609/12/20160912194504_4KxZ2.jpeg";//此处应该通过 API 获取
    if (img_url) {
        [adImageView sd_setImageWithURL:[NSURL URLWithString:img_url]
                              completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
         {
             [UIView beginAnimations:nil context:nil];
             [UIView setAnimationDuration:2];
             adImageView.alpha  = 1;
             [UIView commitAnimations];
         }];
    }
    
    //TODO url 为点击地址的 url
//    if (url && ![url isEqualToString: @""]) {
//        UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(show)];
//        
//        [adImageView addGestureRecognizer:click];
//    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)show
{
    //TODO 点击跳转 webview 页面
//    UWOWebViewController *vc = [[UWOWebViewController alloc] init];
//    vc.url =url;
//    [_myTimer invalidate];
//    [self.navigationController pushViewController:vc animated:YES];
}

-(void)timerFired
{
    UWOTabBarController *vc =[[UWOTabBarController alloc] init];
    
    [[AppDelegate instance] setRootViewController:vc];
    [_myTimer invalidate];
}

@end
